package com.twu.biblioteca;

import javax.jws.soap.SOAPBinding;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Raluca Puichilita on 03/08/2014.
 */

public class UserAccountManager {

    protected List<UserAccount> listOfRegisteredUsers = new ArrayList<UserAccount>();

    public void populateListWithUsers() {
        UserAccount fakeUser1 = new UserAccount("Jane Doe", "jane@yuhu.com", "555-1233");
        addUser(fakeUser1, "123-1234", "myverysecurepassword");

        UserAccount fakeUser2 = new UserAccount("Johnny Doe", "jo_the_doe@test.com", "555-0000");
        addUser(fakeUser2, "111-1111", "pwd");
    }

    public void addUser(UserAccount user, String libraryNo, String pwd) {
        user.setUserLibraryNumber(libraryNo);
        user.setUserPassword(pwd);
        listOfRegisteredUsers.add(user);
    }

    public UserAccount userCredentialsAreValid(String libraryNo, String password) {
        for (UserAccount thisUser : listOfRegisteredUsers) {
            if (checkUserLibraryNo(thisUser, libraryNo))
                if (checkUserPassword(thisUser, password))
                    return thisUser;
        }

        return null;
    }

    public boolean checkUserLibraryNo(UserAccount user, String libraryNo) {
        return (libraryNo.equals(user.getUserLibraryNumber()));
    }

    public boolean checkUserPassword(UserAccount user, String pwd) {
        return (pwd.equals(user.getUserPassword()));
    }

}